package com.quectel.business.common.securitypatrolsubject;

import com.quectel.business.common.util.sys.SysCodeUtils;
import com.quectel.constant.sys.SysCodeKeyConstants;
import com.quectel.core.module.securitypatrol.dto.SecurityPatrolSubjectDto;
import com.quectel.sys.module.sys.dto.SysCodeDto;
import com.quectel.sys.module.sys.service.SysUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 编写说明
 *
 * @author bob
 * @email bob.yu@quectel.com
 * @date 2022/10/17 16:08
 */
@Component
public class SecurityPatrolBussiness {

    @DubboReference
    private SysUserService sysUserService;

    public Byte getChildTypeValue(SecurityPatrolSubjectDto subjectDto) {
        Byte groupType = null;
        List<SysCodeDto> subjectCategory = SysCodeUtils.easyToGetByMark(SysCodeKeyConstants.PATROL_GROUP_CATEGORY);
        if (subjectCategory != null) {
            for (SysCodeDto sysCodeDto : subjectCategory) {
                if (Objects.equals(subjectDto.getCategory() + "", sysCodeDto.getValue())) {
                    List<SysCodeDto> children = sysCodeDto.getChildren();
                    if (children != null) {
                        for (SysCodeDto child : children) {
//                            SysCodeUtils.easyToGetName();
                            if (Objects.equals(child.getName(), subjectDto.getGroupTypeName())) {
                                groupType = Byte.valueOf(child.getValue());
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
        return groupType;
    }

    /**
     * 巡检分类
     *
     * @param subjectDto
     * @return
     */
    public String[] getCategoryAndType(SecurityPatrolSubjectDto subjectDto) {
        String categoryName = "";
        String groupTypeName = "";
        List<SysCodeDto> subjectCategory = SysCodeUtils.easyToGetByMark(SysCodeKeyConstants.PATROL_GROUP_CATEGORY);
        if (subjectCategory != null) {
            for (SysCodeDto sysCodeDto : subjectCategory) {
                if (Objects.equals(subjectDto.getCategory() + "", sysCodeDto.getValue())) {
                    categoryName = sysCodeDto.getName();
                    List<SysCodeDto> children = sysCodeDto.getChildren();
                    if (children != null) {
                        for (SysCodeDto child : children) {
                            if (Objects.equals(child.getValue(), subjectDto.getGroupType() + "")) {
                                groupTypeName = child.getName();
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
        return new String[]{categoryName, groupTypeName};
    }
}
